<!--
To change tdis template, choose Tools | Templates
and open tde template in tde editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=latin1">
        <link rel="stylesheet" type="text/css" href="../padrao.css" />
        <link rel="stylesheet" href="../jQuery/lista.css" type="text/css" media="all" />
        <script type="text/javascript" src="../jQuery/jquery-1.2.1.pack.js"></script>
        <script type="text/javascript" src="../jQuery/busca.js"></script>
        <script type="text/javascript" src="../sorttable.js"></script>

        <title> Template </title>

        <?php
        ob_start();
        include '../infobox.php';
        include '../verifica_usuario.php';
        include '../functions.php';
        include '../functions_office.php';
        include '../menu.php';
        ?>

    </head>
    <body>
        <div class="conteudo">
            <p class="titulopesquisa" align='center'> CREDITOS </p>
            <?php
            //inicializa variavel de ordenaçao
            $ordem = $_SESSION[ordem];
            if ($ordem == "") {
                $ordem = "ASC";
            }
            ///////////

            $orderby = $_GET[orderby];
            if ($orderby == "") {
                $orderby = "EMPRESAS_cpf_cnpj";
            }
            include("mysqlconfig.inc");
            $query = "select * from CREDITOS
                  ORDER BY $orderby $ordem; ";


            $res = mysql_query($query);
            $num_reg = mysql_num_rows($res);


            echo "<table> ";

            //titulos das colunas
            echo "<tr class='titulo'>";
            echo "<td> <a href='?orderby=idcreditos'> ID </a> </td>";
            echo "<td> <a href='?orderby=EMPRESAS_nome'> Nome </a> </td>";
            echo "<td> <a href='?orderby=EMPRESAS_cpf_cnpj'> CPF/CNPJ </a> </td>";
            echo "<td> <a href='?orderby=ATERROS_nome'>Aterro </a> </td>";
            echo "<td> <a href='?orderby=cred_poly'>Creditos Poly </a> </td>";
            echo "<td> <a href='?orderby=cred_truck'>Creditos Truck </a> </td>";
            echo "<td> <a href='?orderby=cred_toco'>Creditos Toco </a> </td>";
            echo "<td> <a href='?orderby=cred_carreta'>Creditos Carreta </a> </td>";
            echo "<td> <a href='?orderby=cred_transbordo'>Creditos Transbordo </a> </td>";
            echo "</tr>";

            for ($i = 0; $i < $num_reg; $i++) {
                $mostra = mysql_fetch_array($res);
                if ($i % 2 == 1) {
                    $tipolinha = "tipo1";
                } else {
                    $tipolinha = "tipo2";
                }
                echo "<tr class='$tipolinha'>";
                echo "<td> $mostra[idcreditos] </td>";
                echo "<td> $mostra[EMPRESAS_nome] </td>";
                echo "<td> $mostra[EMPRESAS_cpf_cnpj] </td>";
                echo "<td> $mostra[ATERROS_nome] </td>";
                echo "<td> $mostra[cred_poly] </td>";
                echo "<td> $mostra[cred_truck] </td>";
                echo "<td> $mostra[cred_toco] </td>";
                echo "<td> $mostra[cred_carreta] </td>";
                echo "<td> $mostra[cred_transbordo] </td>";
                echo "</tr>";
            }
            echo "</table>";
//informa a quantidade de registros encontrados
            echo "$num_reg Registros cadastrados <br>";
//encerra a conexão
            mysql_close($con);
            
            //troca ordenaçao
            if($ordem == "ASC"){
              $ordem = "DESC";
              $_SESSION[ordem] = $ordem;
            }else {
                $ordem = "ASC";
              $_SESSION[ordem] = $ordem;
            }

            ?>
        </div>
    </body>
</html>